package main;

import java.util.*;
import models.*;
import voidlib.*;
/**
 * @author nevidimov
 */
public class BusinessmanController extends VoidController {

    public void listCreditsAction() {
        if (this.isPostRequest()) {
            int bankId = Integer.parseInt(this.request.getParameter("bank_id"));
            int amount = Integer.parseInt(this.request.getParameter("amount"));
            long created = new Date().getTime();
            Credit cr = new Credit(amount, VoidUser.getInstance().getId(), bankId, RequestStatus.Pending, created);
            cr.save();
        }
         
        List<Credit> credits = new Credit().getMapper().fetchAll("businessman_id = ?", VoidUser.getInstance().getId());
        
        this.view.put("credits", credits);
        this.initModelAndView();
    }
    
    public void newCreditAction() {
        List<User> banks = new User().getMapper().fetchAll("role = ?", UserRole.Bank);
        
        this.view.put("banks", banks);
        this.initModelAndView();
    }
    
}
